<template>
  <el-dialog title="人员信息合并" :close-on-click-modal="false" :visible.sync="visible" center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-table :data="dataList" border>
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column type="selection" width="55">
        <template slot-scope="scope">
          <el-radio v-model="targetId" :label="scope.row.id" style="position: relative;left: 6px;top:-2px;" @change="checkItem(scope.row.id)">&nbsp;</el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="80"></el-table-column>
      <el-table-column prop="gender" label="性别" width="50">
        <template slot-scope="scope">
          <span v-if="scope.row.gender == '0'">男</span>
          <span v-if="scope.row.gender == '1'">女</span>
        </template>
      </el-table-column>
      <el-table-column prop="customerCard" label="就诊卡号"></el-table-column>
      <el-table-column prop="telPhone" label="联系方式"></el-table-column>
      <el-table-column prop="birthDay" label="出生年月"></el-table-column>
      <el-table-column prop="uniqueCode" label="编号"></el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-prevent-re-click>确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {mapGetters} from 'vuex'
  import { mergePersonMessage } from '@/api/pvm/person'

  export default {
    data () {
      return {
        visible: false,
        dataList: [],
        targetId: ''
      }
    },
    computed: {
        ...mapGetters(['bizData', 'keyCollapse'])
    },
    methods: {
      init (list) {
        this.visible = true
        this.dataList = list
        this.$nextTick(() => {
        })
      },
      // 表单提交
      dataFormSubmit() {
        let list = []
        this.dataList.forEach(item => {
          list.push(item.id)
        })

        let params = {
          ids: list,
          targetId: this.targetId
        }
        mergePersonMessage(params).then(response => {
          if(response.code==1){
              this.$message.error(response.msg);
          }else{
            this.$message.success('合并成功')
            setTimeout(() => {
              this.visible = false
              this.$emit('refreshData')
            },1500)
          }
        })
      },
      checkItem(id){
        console.log(this.targetId)
      }
    }
  }
</script>
